package com.seecoder.BlueWhale.repository;

import com.seecoder.BlueWhale.po.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Date;

public interface OrderRepository extends JpaRepository<Order, Integer> {
    Order findById(int id);

    List<Order> findAllByOwnerID(Integer id);

    List<Order> findAllByStoreID(Integer storeID);

    @Query("SELECT o FROM Order o WHERE o.status = 'UNPAID' AND o.createTime < :date")
    List<Order> findUnpaidOrdersBefore(Date date);

    @Query("SELECT o FROM Order o WHERE o.id = (SELECT MAX(o2.id) FROM Order o2)")
    Order findWithMaxId();
}